<%@ page import="java.util.LinkedHashMap,
				 java.util.Iterator,
				 java.util.ArrayList,
				 com.scalar.chiptrack.adaptor.Adaptor,
                 com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.adaptor.AdaptorList" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<% String chipTracContext = "/" + ConfigManager.getChipTracContext(); %>
<% //String servletUrlPath =  "http://"+ request.getServerName()+":"+ request.getServerPort()+request.getContextPath();
    String servletUrlPath = request.getScheme() + "://"+ request.getServerName()+":"+ request.getServerPort()+request.getContextPath();    
%>

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>

<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>

<script language="javascript">

var text = "";
var errtext = "";
var pa = "";

function debugInfo(message)
{
    if( message.indexOf("<") > -1 )
    {
        errtext +=message+"\n";
        pa=document.getElementById("errors");
        pa.innerHTML = errtext;
    }

    text +=message+"\n";
	//document.all["debug"].innerHTML = text;
	document.run_adaptor_form.debugarea.value = text;
}


function submit()
{
    var adaptorNameString = "";
    errtext = "";
    pa.innerHTML = "";


    if(typeof document.run_adaptor_form.adaptorNames.length == 'undefined')
    {
        document.run_adaptor_form.adaptorNames.disabled = true;
        if( document.run_adaptor_form.adaptorNames.checked )
        {
            var adaptorName = document.run_adaptor_form.adaptorNames.value;
            adaptorNameString = adaptorNameString +adaptorName +",";
        }
    }
    else
    {
 	    for( var i = 0; i < document.run_adaptor_form.adaptorNames.length; i++ )
        {
            document.run_adaptor_form.adaptorNames[i].disabled = true;
            if( document.run_adaptor_form.adaptorNames[i].checked )
            {
                var adaptorName = document.run_adaptor_form.adaptorNames[i].value;
                adaptorNameString = adaptorNameString +adaptorName +",";
            }
        }
    }

    if( adaptorNameString.length > 0 )
    {
         debugInfo("Initializing server");
        if( document.proxy.startCommunicator() == "success" )
         {
            debugInfo("Sending Request to server......");
  		 }

        //debugInfo( "Processing Request......."+adaptorName );
 		document.proxy.startRequest( adaptorNameString );

        while( document.proxy.waitForResponse() != false )
        {
            debugInfo( document.proxy.receiveResponse() );
 		}

        if( document.proxy.endRequest() == "end" )
        {
            debugInfo( "request end" );
 		}
    }

    if(typeof document.run_adaptor_form.adaptorNames.length == 'undefined')
    {
        document.run_adaptor_form.adaptorNames.disabled = false;
    }
    else
    {
        for( var i = 0; i < document.run_adaptor_form.adaptorNames.length; i++ )
        {
            document.run_adaptor_form.adaptorNames[i].disabled = false;
        }
    }
    if( adaptorNameString.length <= 0 )
    {
        pa=document.getElementById("errors");
        pa.innerHTML = "Please select atleast one vendor";
    }
 }


</script>
</HEAD>
<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">
<!-- Top Header Start-->
<%@include file="/jsp/includes/extHeader.jsp"  %>
<!-- Top Header End-->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border="0">
    <TBODY>
    <TR>
        <td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
        <!-- Side Navigation start -->
            <%@ include file="/jsp/admin/externaluser_menu.jsp" %>
        </TD>
        <!-- end of the side navigations -->
        <TD bgcolor="#ffffff">
        <IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
        <TD valign="top" width="100%">

        <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
        <!--<BR>-->
            <form name="run_adaptor_form"  action="<%=chipTracContext%>/runAdaptor.do">
            <table border="0" width="90%" align=center>
                <tr>
                    <td colspan="3" class="NArialW" align="center">On Demand Adaptor</td>
                </tr>
                <tr><td colspan="3" class="NArialW" align="center">&nbsp;</td></tr>
                <tr><td colspan="3" class="NArialL" align="left"><FONT id="errors" styleClass="NArialL" color='FF0000'></FONT></td></tr>
                <tr>
                    <td width="30%">
                        <table align=left border=0 valign=top>
                            <bean:size id="adaptorListSize" name="adaptorMap" />
                            <logic:greaterThan name="adaptorListSize" value="0">
                                <logic:iterate id="adaptor" name="adaptorMap">
                                    <tr>
                                        <td width="30%">
                                            <input type="checkbox" name="adaptorNames" value='<bean:write name="adaptor" property="key"/>'>
                                            <font class="NArialL"><bean:write name="adaptor" property="key"/></font>
                                        </td>
                                    </tr>
                                </logic:iterate>
                            </logic:greaterThan>
                            <logic:equal name="adaptorListSize" value="0">
                                <tr><td width="30%"><font class="NArialL"><font color="red">No Vendors</font></font></td></tr>
                            </logic:equal>

                            <%--<bean:size id="fgSize" name="fgAdaptorList" />
                            <logic:greaterThan name="fgSize" value="0">
                                <logic:iterate id="fgAdaptor" name="fgAdaptorList"  type="com.scalar.chiptrack.operations.vendor.Vendor">
                                    <tr>
                                        <td width="30%">
                                            <input type="checkbox" name="adaptorNames" value='<bean:write name="fgAdaptor" property="vendorName" />'>
                                            <font class="NArialL"><bean:write name="fgAdaptor" property="vendorName" /></font>
                                        </td>
                                    </tr>
                                </logic:iterate>
                            </logic:greaterThan>
                            <logic:equal name="fgSize" value="0">
                                <tr><td width="30%"><font class="NArialL"><font color="red">No Vendors</font></font></td></tr>
                            </logic:equal>--%>
                            <tr>
                                <td align=center>
                                    <IMG height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1><br>
                                    <logic:greaterThan name="adaptorListSize" value="0">
                                        <a href="javascript:submit()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17" onmouseover="window.status='Click to Run Adaptors';return true" onmouseout="window.status='';return true" title="Click here to Run Adaptors"></a>
                                    </logic:greaterThan>
                                </td>
                            </tr>
                            <tr><td align=right width="20%">&nbsp;</td></tr>
                        </table>
                    </td>
                    <td width="2%">&nbsp;</td>
                    <td width="68%" valign="top"><div id=debug><textarea name=debugarea rows=20 cols=75 class="txfield" readonly=true autoscroll></textarea></div></td>
                </tr>
                <tr>
                    <td colspan=3>
                        <OBJECT name=proxy classid="clsid:CAFEEFAC-0016-0000-FFFF-ABCDEFFEDCBA"
                          height="0"
                          width="0"
                          codebase="http://java.sun.com/update/1.6.0/jinstall-6-windows-i586.cab">
                            <PARAM NAME="code" VALUE="com.scalar.chiptrack.workflow.RunAdaptorApplet.class">
                            <PARAM NAME="codebase" VALUE="<%=chipTracContext%>">
                            <PARAM NAME="name" VALUE="proxy">
                            <PARAM name="type" value="application/x-java-applet;version=1.6">
                            <PARAM NAME="archive" VALUE="workflow.jar">
                            <param name="contextURL" value="<%=servletUrlPath%>" >
                        </OBJECT>
                    </td>
                </tr>
            </table>
            <input type="hidden" name="action">
            </form>
        </TD>
    </TR>
    </TBODY>
</TABLE>
</BODY>
</HTML>
